var app = getApp()
var tcity = require("../../../../utils/citys.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    provinces:[],//省份
    provincesdex:0,
    citys:[],//城市
    citysdex:0,
    needFix: false,
    bannerHeight: 0,
    tabdex: "",
    popshow: false,
    tablist: ["全部地区","综合排序"],
    sortlists:[
      { items: "甲等医院", checked: false },
      { items: "二甲医院", checked: false },
      { items: "三甲医院", checked: false },
      { items: "儿童医院", checked: false },
      { items: "骨科甲医院", checked:false},
    ],
    hospitallm:[
      {
        id:85,
        name:"三甲医院",
      }, {
        id: 85,
        name: "三甲医院",
      }, {
        id: 85,
        name: "三甲医院",
      }, {
        id: 85,
        name: "三甲医院",
      }, {
        id: 85,
        name: "三甲医院",
      }, {
        id: 85,
        name: "三甲医院",
      }, {
        id: 85,
        name: "三甲医院",
      }, {
        id: 85,
        name: "三甲医院",
      }, {
        id: 85,
        name: "三甲医院",
      }, {
        id: 85,
        name: "三甲医院",
      }, {
        id: 85,
        name: "三甲医院",
      }, {
        id: 85,
        name: "三甲医院",
      }, {
        id: 85,
        name: "三甲医院",
      }, {
        id: 85,
        name: "三甲医院",
      }, {
        id: 85,
        name: "三甲医院",
      }, {
        id: 85,
        name: "三甲医院",
      }, {
        id: 85,
        name: "三甲医院",
      }, {
        id: 85,
        name: "三甲医院",
      }, {
        id: 85,
        name: "三甲医院",
      }, {
        id: 85,
        name: "三甲医院",
      }, {
        id: 85,
        name: "三甲医院",
      }, {
        id: 85,
        name: "三甲医院",
      }, {
        id: 85,
        name: "三甲医院",
      }, {
        id: 85,
        name: "三甲医院",
      }, {
        id: 85,
        name: "三甲医院",
      }, {
        id: 85,
        name: "三甲医院",
      }, {
        id: 85,
        name: "三甲医院",
      }, {
        id: 85,
        name: "三甲医院",
      }, {
        id: 85,
        name: "三甲医院",
      }, {
        id: 85,
        name: "三甲医院",
      }, {
        id: 85,
        name: "三甲医院",
      }, {
        id: 85,
        name: "三甲医院",
      },
    ]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var that = this
    var bgc = wx.getStorageSync('color')
    wx.setNavigationBarColor({
      frontColor: "#ffffff",
      backgroundColor: bgc,
    })
    app.util.request({
      'url': 'entry/wxapp/Hospatillianmengall',
      success: function(res) {
        console.log(res)
        // that.setData({
        //   hospitallm: res.data.data
        // })
      }
    })
    tcity.init(that);
    var cityData = that.data.cityData;
    const provinces = [];
    const citys = ["全国", "北京", "上海", "广州", "杭州", "西安", "武汉"];
    provinces.push("热门城市");
    for (let i = 0; i < cityData.length; i++) {
      provinces.push(cityData[i].name);
    }
    that.setData({
      provinces,
      citys
    })
  },
  //选择省份
  provinceitem(e){
    var val = e.currentTarget.dataset.dex
    var t = this.data.provincesdex;
    var cityData = this.data.cityData;
    if (val != t){
      if (val>0){
        let ci = val-1
        let citys = [];
        for (let i = 0; i < cityData[ci].sub.length;i++){
          citys.push(cityData[ci].sub[i].name)
        }
        this.setData({
          citys,
          provincesdex: val
        })
      }else if(val == 0){
        let citys = ["全国", "北京", "上海", "广州", "杭州", "西安", "武汉"];
        this.setData({
          citys,
          provincesdex: val
        })
      }
    }
  },
  //城市
  cityitem(e){
    var val = e.currentTarget.dataset.dex
    var name = e.currentTarget.dataset.name
    let tablist = this.data.tablist
    tablist[0] = name
    this.setData({
      tablist,
      citysdex: val,
      popshow:false,
      tabdex:""
    })
  },
  hzanl(e) {
    wx.navigateTo({
      url: "/hyb_yl/userLife/pages/faxian/faxian?long='long'",
    })
  },
  // tab切换
  tabbtn(e) { 
    if (e.currentTarget.dataset.dex === this.data.tabdex) {
      this.setData({
        popshow: false,
        tabdex: "",
      })
    } else {
      wx.pageScrollTo({
        scrollTop: 100,
      })
      this.setData({
        popshow: true,
        tabdex: e.currentTarget.dataset.dex,
      })
    }
  },
  // tab选项
  itemchecked(e) {
    let arrs = this.data.sortlists, i = this.data.tabdex, dex = e.currentTarget.dataset.dex, tabs = this.data.tablist
    arrs.map(item => {
      item.checked = false
    })
    tabs[i] = arrs[dex].items
    arrs[dex].checked = true
    this.setData({
      tablist: tabs,
      sortlists: arrs,
      popshow: false,
      tabdex: ""
    })
  },
  hidepop() {
    this.setData({
      popshow: false,
      tabdex: ""
    })
  },
  onPageScroll(e) {
    let h = e.scrollTop; let needFix = this.data.needFix; let bannerHeight = this.data.bannerHeight;
    if (h > 10 + bannerHeight) {
      this.setData({
        needFix: true
      })
    } else if (h < 20) {
      this.setData({
        needFix: false,
      })
    }
    this.setData({
      bannerHeight: h
    })
  },
  preventTouchMove(){},
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },


})